package com.yxw.yxnet_cd_center.customer_service.controller;

import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import com.yxw.yxnet_cd_center.customer_service.dto.UserWorkUpdateDTO;
import com.yxw.yxnet_cd_center.customer_service.service.UserWorkService;
import com.yxw.yxnet_cd_center.customer_service.vo.UserWorkInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author fangmaoxin
 * @version 1.0
 * @date 2023年9月14日
 * 客服工作设置
 */
@RestController
@Api(value = "客服工作设置", tags = "客服管理")
@Slf4j
@RequestMapping("/userWork/v1")
public class UserWorkController {

    @Autowired
    private UserWorkService userWorkService;

    /**
     * 登录成功后获取当前登录客服的设置信息
     */
    @ApiOperation(value = "获取客服设置")
    @PostMapping(value = "/getUserWorkInfoByUserId/{userId}")
    public BaseResult getUserWorkInfoByUserId(@PathVariable Long userId) {
        UserWorkInfoVo result = userWorkService.getUserWorkInfoByUserId(userId);
        return BaseResult.doSuccess(result,"获取客服设置成功！");
    }

    /**
     * 修改客服设置信息
     */
    @ApiOperation(value = "修改客服设置")
    @PostMapping(value = "/update/{userId}")
    public BaseResult updateUserWorkInfo(@Validated @RequestBody UserWorkUpdateDTO updateDTO,@PathVariable Long userId) {
        if (updateDTO.getWorkId() != null) {
            userWorkService.update(updateDTO,userId);
        } else {
            userWorkService.save(updateDTO,userId);
        }
        return BaseResult.doSuccess(null,"操作客服设置成功！");
    }

}
